Переменной Z присвоить значение наибольшего из элементов матрицы {Ai,j} 4,4 , расположенные выше главной диагонали — С++(Си)

#include <iostream>
#include <time.h>
const int N=20; //константный размер матрицы (можно менять)
using namespace std;
int main()
{
        srand (time(NULL)); 
    int matr[N][N]; 
    int i, j, n=4, k, z; 
 
//формируем матрицу случайных чисел
        cout<<"Matrica: "<<endl;
    for(i = 0; i < n; ++i) 
                for(j = 0; j < n; ++j) 
                        matr[i][j]=1+rand()%15;
//печать матрицы
        for(i = 0; i < n; ++i)  
        {
                for(j = 0; j < n; ++j) 
                        cout<<matr[i][j]<<"\t"; 
                cout<<endl; 
        }
        z=matr[0][1];
        cout<<"prosmatrivaemye chisla: \n";
        for (j=1, k=1; j<n; j++, k++)
            for (i=0; i<k; i++)
            {
                cout<<matr[i][j]<<" ";
                if (matr[i][j]>z)
                    z=matr[i][j];
            }
        cout<<"\nz: "<<z<<endl;
 
    return 0;
}

Leave a Comment